package com.zito.health.core.shiro;

import com.zito.health.core.util.DigestsUtil;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;

/**
 * @description:
 * @author: gxt
 * @time: 2019/10/12 11:13
 */
public class CustomCredentialsMatcher extends HashedCredentialsMatcher {

    @Override
    public boolean doCredentialsMatch(AuthenticationToken authcToken, AuthenticationInfo info) {
        ZitoToken token = (ZitoToken) authcToken;
        Object accountCredentials = getCredentials(info); // 数据库密码
        //将密码加密与系统加密后的密码校验，内容一致就返回true,不一致就返回false
        return DigestsUtil.validatePassword(String.valueOf(token.getPassword()), accountCredentials + "");
//        return (accountCredentials+"").equals(DigestsUtil.md5(String.valueOf(token.getPassword()).getBytes()));

    }
}
